package com.spring.security.client;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @author seabed_moon
 */
@SpringBootApplication
@RestController
@ComponentScan("com.sunlands")
public class SecurityClientApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(SecurityClientApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    @Autowired
//    private SecurityProperties securityProperties;

    @GetMapping("/hello")
    public String hello() {
        return "hello security";
    }

    @GetMapping("/user")
    public Object user(Authentication authentication, HttpServletRequest request) throws UnsupportedEncodingException {
//        String token = StringUtils.substringAfter(request.getHeader("Authorization"), "bearer ");
//        Claims claims = Jwts.parser().setSigningKey(securityProperties.getOauth2().getJwtSigningKey().getBytes("UTF-8")).parseClaimsJws(token).getBody();
//        System.out.println(claims);
        return authentication;

    }

}
